﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>判断用户输入是否为中文</title>
    <script type="text/javascript" language="JavaScript">
        function ischinese(s){
            let res = true;
            for(let i = 0;i<s.length;i++){
                res = res && (s.charCodeAt(i)>=10000);
            }
            return res;
        }
        function chk(str){
            let val = ischinese(str);
            if(!val){
                alert("您输入的字符不是全中文");
            }else{
                alert("您输入的字符是全中文");
            }
        }
        
    </script>
</head>
<body>
<input type=text name="txt1" value="this is test!">
<input type=button value="转换文本" onClick="javascript:chk(txt1.value)">
</body>
</html>